/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class HunanSearchEngine extends SearchEngine
/*     */ {
/*  36 */   private static Logger logger = Logger.getLogger(HunanSearchEngine.class
/*  37 */     .getName());
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*  27 */     HunanSearchEngine searchEngine = new HunanSearchEngine("湖南易科生物工程有限公司");
/*     */     try {
/*  29 */       searchEngine.getCompanyInfo(true);
/*     */     }
/*     */     catch (CaptchaException e) {
/*  32 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public HunanSearchEngine(String name)
/*     */   {
/*  40 */     this.name = standardizedName(name);
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */   {
/*  45 */     if (!isValid(this.name)) {
/*  46 */       return null;
/*     */     }
/*  48 */     String url = null;
/*     */     try {
/*  50 */       url = "http://www.hnaic.gov.cn/visit/socialservice/a/listEnterpriseForAjax?nocache=1373953906130&keyselect=null&marktype=1&page=1&key=" + 
/*  51 */         URLEncoder.encode(this.name.trim(), "utf-8").replace("%", 
/*  52 */         "%25");
/*     */     } catch (UnsupportedEncodingException e) {
/*  54 */       url = "http://www.hnaic.gov.cn/visit/socialservice/a/listEnterpriseForAjax?nocache=1373953906130&keyselect=null&marktype=1&page=1&key=" + this.name.trim();
/*     */     }
/*     */     try {
/*  57 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  58 */         .timeout(10000).get();
/*  59 */       Element link = doc.select("priid").first();
/*  60 */       String id = null;
/*  61 */       if (link != null)
/*     */       {
/*  63 */         id = link.text();
/*     */       }
/*     */ 
/*  66 */       if ((id == null) || (id.trim().length() == 0)) {
/*  67 */         return null;
/*     */       }
/*     */ 
/*  70 */       String detailUrl = "http://www.hnaic.gov.cn/visit/socialservice/a/listEntSingleForAjax?nocache=1373954782518&markid=" + id;
/*     */ 
/*  72 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  73 */         .get();
/*     */ 
/*  75 */       String all = doc.text();
/*     */ 
/*  77 */       if (all == null) {
/*  78 */         return null;
/*     */       }
/*     */ 
/*  81 */       String[] items = all.split("hnaicfzn");
/*  82 */       Map info = new HashMap();
/*     */ 
/*  84 */       info.put("SN", items[0]);
/*  85 */       info.put("CompanyName", items[1]);
/*  86 */       info.put("Address", items[2]);
/*  87 */       info.put("Header", items[4]);
/*  88 */       info.put("CompanyType", items[5]);
/*  89 */       info.put("RegisteredCapital", items[6] + "万元");
/*  90 */       info.put("BusinessScope", items[7]);
/*  91 */       info.put("FoundedDate", items[9]);
/*  92 */       info.put("RegistrationAuthority", items[12]);
/*  93 */       info.put("UpdateDate", Util.date2Str(new Date()));
/*  94 */       if (info.size() > 1)
/*     */       {
/*  96 */         saveDB(info);
/*     */       }
/*     */ 
/*  99 */       return info;
/*     */     } catch (IOException e) {
/* 101 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 104 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.HunanSearchEngine
 * JD-Core Version:    0.6.1
 */